Flutter 版 Rive Native
一个 Flutter 插件,集成了 Rive 渲染器和核心 Rive C++ 运行时。由 Rive Flutter 运行时使用。
Rive Native 与 Rive 的区别
Rive Native(rive_native)是一个 Flutter 插件,集成了 Rive 渲染器和核心 Rive C++ 运行时。
Rive Flutter 运行时(rive)构建在 rive_native 之上。我们建议将 rive 包作为依赖项包含,因为它会自动包含 rive_native,同时还提供了在 Flutter 中处理 Rive 资源的用户友好 API。
Rive Native 取代了 Rive Flutter 之前用于原生操作的 Rive Common(
rive_common)插件。
理解 Rive Native
Rive Native 充当 Flutter 与 Rive C++ 运行时之间的桥梁,允许你在 Flutter 应用中使用 Rive 图形。
-
C++ 运行时集成:
rive_native通过 FFI 基于 Rive 的 C++ 运行时构建。这确保了跨平台和 Rive 编辑器的一致体验,同时解锁了 C++ 运行时独有的性能改进和新功能,例如: -
Rive 渲染器支持:
rive_native将 Rive 渲染器带入 Flutter。虽然你仍然可以使用基于 Flutter 的渲染器(Dart/Impeller),但对于性能关键的使用场景,建议使用 Rive 渲染器。更多信息请参见选择渲染器。某些功能(如矢量羽化)仅在 Rive 渲染器下受支持。详情请参见功能支持页面。
入门指南
rive_native 目前尚未在 GitHub 上公开发布,但即将发布。目前,你可以通过运行以下命令拉取源代码和示例:
dart pub unpack rive_native # 解压包源代码和示例应用
cd rive_native/example # 导航到示例文件夹
flutter create . # 创建平台文件夹
flutter pub get # 获取依赖
flutter run # 运行示例应用
有关示例实现,请参见 rive_native/example/rive_player.dart 中的 rive_player.dart 文件。
平台支持
| 平台 | Flutter 渲染器 | Rive 渲染器 |
|---|---|---|
| iOS | ✅ | ✅ |
| Android | ✅ | ✅ |
| macOS | ✅ | ✅ |
| Windows | ✅ | ✅ |
| Linux | ❌ | ❌ |
| Web | ✅ | ✅ |
功能支持
详情请参见功能支持页面。
故障排查
所需的原生库应在构建步骤(flutter run 或 flutter build)中自动下载。如果遇到问题,请尝试以下步骤:
- 运行
flutter clean - 运行
flutter pub get - 运行
flutter run
或者,你可以手动运行 rive_native 设置脚本。在 Flutter 应用的根目录中执行:
dart run rive_native:setup --verbose --clean --platform macos
这将清除 rive_native 设置并下载由 --platform 标志指定的平台特定库。请参阅上文的平台支持部分了解详情。
Android
如果你遇到自动化设置问题(示例问题 555 和 515),
可以通过在应用的 gradle.properties 中设置 rive.native.skipSetup=true 来跳过设置。
启用后,你必须手动运行 dart run rive_native:setup --verbose --clean --platform android 来下载所需的库。
构建 rive_native
默认情况下,会下载并使用预构建的原生库。如果你想自己构建库,请在设置脚本中使用 --build 标志:
flutter clean # 重要
dart run rive_native:setup --verbose --clean --build --platform macos
注意:构建库需要机器上安装特定的工具。更多文档即将提供。
测试
共享库包含在下载/构建过程中。如果你在测试中使用 rive_native 时遇到问题,请联系我们获取帮助。